package com.jollychic.www.roomdatebasedemo.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jollychic.www.roomdatebasedemo.R;
import com.jollychic.www.roomdatebasedemo.model.StoreEntity;

import java.util.List;

/**
 * desc:  <br/>
 * author: 李超杰 <br/>
 * time: 2018/4/22 18:50 <br/>
 * since: V 6.1X <br/>
 */

public class AdapterList extends RecyclerView.Adapter<AdapterList.InnerHolder> {

    private final List<StoreEntity> LIST;
    private final Context CONTEXT;

    public AdapterList(Context context, List<StoreEntity> list) {
        this.CONTEXT = context;
        this.LIST = list;
    }

    public static final AdapterList createAdapter(Context context, List<StoreEntity> list) {
        return new AdapterList(context, list);
    }


    @Override
    public InnerHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        final View view = LayoutInflater.from(CONTEXT).inflate(R.layout.item_list, parent, false);
        final InnerHolder innerHolder = new InnerHolder(view);
        return innerHolder;
    }

    @Override
    public void onBindViewHolder(InnerHolder holder, int position) {
        final StoreEntity storeEntity = LIST.get(position);
        holder.tvStoreId.setText(storeEntity.getStoreId());
        holder.tvStoreName.setText(storeEntity.getStoreName());
    }

    @Override
    public int getItemCount() {
        return LIST.size();
    }

    public static final class InnerHolder extends RecyclerView.ViewHolder {
        AppCompatTextView tvStoreId;
        AppCompatTextView tvStoreName;

        @SuppressLint("WrongViewCast")
        public InnerHolder(View itemView) {
            super(itemView);
            tvStoreId = itemView.findViewById(R.id.tv_store_id);
            tvStoreName = itemView.findViewById(R.id.tv_store_name);
        }
    }
}
